package br.com.naybee.framework.client.connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import br.com.naybee.framework.client.models.ModelError;
import br.com.naybee.framework.client.utils.NAYException;

@Service
public class ConnectionDb {

	@Autowired
	private static PropertiesNaybee propertiesNibee = new PropertiesNaybee();
	private static Connection connection;

	public static Connection conectando() throws SQLException {
		connection = null;
		try {
			Class.forName(propertiesNibee.getDriver());
			connection = DriverManager.getConnection(propertiesNibee.getUrl(), propertiesNibee.getUsuario(), propertiesNibee.getSenha());
		} catch (ClassNotFoundException e) {
			throw new NAYException(ModelError.GENERAL, e.getMessage());
		}
		return connection;
	}

}
